index_counter = {}

with open('../index_result.txt', 'r', encoding='utf8') as f:
    total = 0
    for line in f:
        line_split = line.split('=')
        if len(line_split[0]) < 5:
            continue
        secret_card = line_split[0]
        index = int(line_split[1])

        start_char = secret_card[0]
        if start_char not in index_counter:
            index_counter[start_char] = 0
        index_counter[start_char] += 1
        total += 1
        if total % 100000 == 0:
            print('total is {}'.format(total))

print('write index count result to file')
with open('../index_counter.txt', 'w', encoding='utf8') as f:
    for start_char, count in index_counter.items():
        f.write('{}={}\n'.format(start_char, count))

print('finish...')